﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
using System.ComponentModel;

public partial class frmDiagnosisList : BaseWinFrom
{

    public frmDiagnosisList()
    {
        this.InitializeComponent();
        new TextBoxBindMonthCalendar(txtCreateDate);
    }

    public frmDiagnosisList(string UserId, string UserName, string SerachBeginDate, string SearchEndDate)
        : this()
    {
        txtUserId.Text = UserId;
        txtUserName.Text = UserName;
        Bind();
    }

    private void btSearch_Click(object sender, EventArgs e)
    {
        Bind();
    }

    private void Bind()
    {
        this.dgvDiagnosisList.AutoGenerateColumns = false;



        Model.Search.DiagnosisList dl = new Model.Search.DiagnosisList();


        if (!string.IsNullOrEmpty(txtUserId.Text))
        {
            dl.PatientId = txtUserId.Text;
        }
        if (!string.IsNullOrEmpty(txtUserName.Text))
        {
            dl.PatientName = txtUserName.Text;
        }
        if (!string.IsNullOrEmpty(txtTelephone.Text))
        {
            dl.PatientMobile = txtTelephone.Text;
        }
        if (!string.IsNullOrEmpty(txtCreateDate.Text))
        {
            DateTime dt;
            if (DateTime.TryParse(txtCreateDate.Text, out dt))
            {
                dl.MinCreate = FastJSON.PHP_DateTimeTransform.PHP_DT2LN(dt).ToString();
                dl.MaxCreate = FastJSON.PHP_DateTimeTransform.PHP_DT2LN(dt.AddDays(1)).ToString();
            }
        }
        switch (cbbStatus.SelectedIndex)
        {
            case 1:
                dl.Status = "1";
                break;
            case 2:
                dl.Status = "-1";
                break;
        }

        this.dgvDiagnosisList.DataSource = new BindingList<Model.Diagnosis>(new RST.Diagnosis().List(dl));
    }

    private void dgvDiagnosisList_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.RowIndex < 0)
            return;
        object o = dgvDiagnosisList.Rows[e.RowIndex].Cells[0].Value;
        switch (e.ColumnIndex)
        {
            case 6:
                if (MessageBox.Show("确定删除", "删除", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    new RST.Diagnosis().Delete(new Model.Diagnosis() { Id = o.ToString() });
                    Bind();
                }
                break;
            case 7:
                new frmDiagnosis(o.ToString()).Show();
                break;
            case 8:
                IList<Model.Diagnosis> li = dgvDiagnosisList.DataSource as IList<Model.Diagnosis>;
                Model.Diagnosis d = li[e.RowIndex];
                new frmDiagnosis(new Model.Diagnosis { PatientId = d.PatientId, DiagnosisUserBase = li[e.RowIndex].DiagnosisUserBase }).Show();
                break;
        }
    }

    private void txtCreateDate_Enter(object sender, EventArgs e)
    {

    }

    private void mcd_DateSelected(object sender, DateRangeEventArgs e)
    {
        txtCreateDate.Text = e.Start.ToString("yyyy-MM-dd 00:00:00");
        ((Control)sender).Visible = false;
    }

    private void mcd_MouseLeave(object sender, EventArgs e)
    {
        txtCreateDate.Text = string.Empty;
        ((Control)sender).Visible = false;
    }

    private void btInsert_Click(object sender, EventArgs e)
    {
        new frmDiagnosis(new Model.Diagnosis() { Status = 1 }).Show();
    }
}